﻿using NexTrackDesktop.Media;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using NexTrackDesktop.NexTrack;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using Moq;

namespace NexTrackDesktopTest
{
    
    
    /// <summary>
    ///This is a test class for PlaylistTest and is intended
    ///to contain all PlaylistTest Unit Tests
    ///</summary>
    [TestClass()]
    public class PlaylistTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for AddSong
        ///</summary>
        [TestMethod()]
        public void AddSongTest()
        {
            var mAdapter = new Mock<MainServiceAdapter>();
            var target = new Playlist_Accessor(mAdapter.Object);
            Song s = new Song() { SongID = "testAddSong" };

            target.AddSong(s);

            Assert.AreEqual(1, target.Items.Count);
            Assert.AreEqual(s, target.Items[0]);
            mAdapter.Verify(m => m.AddSong(s), Times.Once());
        }

        /// <summary>
        ///A test for AddSongs
        ///</summary>
        [TestMethod()]
        public void AddSongsTest()
        {
            var mAdapter = new Mock<MainServiceAdapter>();
            var target = new Playlist_Accessor(mAdapter.Object);

            var testSongs = new List<Song>() 
            { 
                new Song() {SongID = "testAddSong" },
                new Song() {SongID = "testAddSong2" },
                new Song() {SongID = "TestAddSong3"},
            };

            target.AddSongs(testSongs);

            Util.AssertAllEqual(testSongs, target.Items);

            //Vertify that each song was added exactly once
            mAdapter.Verify(m => m.AddSong(testSongs[0]), Times.Once());
            mAdapter.Verify(m => m.AddSong(testSongs[1]), Times.Once());
            mAdapter.Verify(m => m.AddSong(testSongs[2]), Times.Once());
            mAdapter.Verify(m => m.AddSong(It.Is<Song>(x => !testSongs.Contains(x))), Times.Never());

        }

        /// <summary>
        ///A test for RemoveSong
        ///</summary>
        [TestMethod()]
        public void RemoveSongTest()
        {
            //MainServiceAdapter serviceAdapter = null; // TODO: Initialize to an appropriate value
            //Playlist target = new Playlist(serviceAdapter); // TODO: Initialize to an appropriate value
            //Song song = null; // TODO: Initialize to an appropriate value
            //target.RemoveSong(song);
            Assert.Inconclusive("A method that does not return a value cannot be verified.");
        }
    }
}
